/**
 * @author zlss
 * @date 2025/5/31
 * @description
 */
import javafx.scene.control.Label;
import javafx.scene.input.KeyEvent;
import javafx.scene.text.Font;

public class Cell extends Label {
    private int row;
    private int col;
    private boolean editable;

    public Cell(int row, int col) {
        this.row = row;
        this.col = col;
        this.editable = true;

        // 设置单元格样式
        setStyle("-fx-border-color: black; -fx-border-width: 1px;");
        setFont(Font.font(20));
        setAlignment(javafx.geometry.Pos.CENTER);

        // 添加键盘事件处理
        addEventFilter(KeyEvent.KEY_PRESSED, e -> {
            if (!editable) {
                e.consume();
            }
        });
    }

    public int getRow() {
        return row;
    }

    public int getCol() {
        return col;
    }

    public boolean isEditable() {
        return editable;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
        if (!editable) {
            setStyle(getStyle() + "-fx-text-fill: black;");
        } else {
            setStyle(getStyle().replaceAll("-fx-text-fill:[^;]+;", ""));
        }
    }
}
